package com.AEWMS.Servlet;

import com.AEWMS.Dao.Attendance;
import com.AEWMS.Service.AttendanceWarningService;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RecordAttendServlet", urlPatterns = "/RecordAttendServlet")
public class RecordAttendServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AttendanceWarningService s  = new AttendanceWarningService();
        Attendance a = new Attendance();
        String SNum = request.getParameter("studentNumber");
        String semesterId = request.getParameter("semesterId");
        String week = request.getParameter("week");
        String typeId = request.getParameter("typeId");
        String  times = request.getParameter("times");
        int time = Integer.parseInt(times); //转换为整数
        String note = request.getParameter("note");
        a.setStudentNumber(SNum);
        a.setSemester(semesterId);
        a.setWeek(week);
        a.setAttendanceTypeId(typeId);
        a.setAttendanceTimes(time);
        a.setAttendanceNote(note);
        if (s.insertAttend(a)){
            response.getWriter().println(JSON.toJSONString("新增成功"));
        } else {
            response.getWriter().println(JSON.toJSONString("新增失败"));
        }
        s.closeCon();
    }
}
